/**
 * Created by hua on 2016/6/29.
 */
var _gl = window._gl || {};
_gl.lang_type="zh-CN";
_gl.environment="local";
_gl._host_res="";
_gl._version="";

// 根据配置加载所需模块
var scripts = document.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
    // 获取页面所需加载模块入口名称
    _gl.pageid = scripts[i].getAttribute("data-pageId") || "";
    if (_gl.pageid) {
        _gl._version = scripts[i].getAttribute("data-version") || "1.0";
        _gl._host_res = scripts[i].getAttribute("data-host") ||"";
        _loadPageScript(_gl.pageid);
        break;
    }
}

console.log(_gl._host_res );

requirejs.config({
    baseUrl: _gl._host_res || '',
    paths: {
        /*工具类配置*/
        zepto: 'js/lib/zepto.min',
        touch: 'js/lib/touch-0.2.10',
        sm: 'js/lib/sm.min',
        smExtend: 'js/lib/sm-extend.min',
        smCityPicker: 'js/lib/sm-city-picker.min',

        base:'js/base',
        index:'js/index',

        account:'js/account/index',
        author:'js/author/index',
        product:'js/product/index',
        broadcast:'js/product/broadcast',
        reading:'js/product/reading',
        payment:'js/payment/index'
    },
    shim: {
        "sm": {deps: ["zepto"]},
        "smExtend": {deps: ["sm"]},
        "smCityPicker": {deps: ["sm"]},
        "touch": {deps: ["zepto"]},
        "base": {deps: ["zepto","sm"]},
        "index": {deps: ["zepto","smExtend","base"]},
        "account": {deps: ["zepto","smExtend","smCityPicker","base"]},
        "author": {deps: ["zepto","smExtend","base"]},
        "product": {deps: ["zepto","smExtend","base","touch"]},
        "broadcast": {deps: ["zepto","smExtend","base"]},
        "reading": {deps: ["zepto","smExtend","base"]},
        "payment": {deps: ["zepto","smExtend", "smCityPicker","base"]}
    },
    waitSeconds:0,
    urlArgs: 'v='+ _gl._version // 修改这里的版本号
});

function _loadPageScript(pageid) {
    switch (pageid) {
        case "index":  //首页
            require(['zepto', 'sm', 'smExtend', 'base', "index"], function () {
                console.log('load complete');
            });
            break;
        case "account":  //会员中心
            require(['zepto', 'sm', 'smExtend', 'smCityPicker', 'base', "account"], function () {
                console.log('load complete');
            });
            break;
        case "register":  //成为会员
            require(['zepto', 'sm', 'smExtend', 'base', "account"], function () {
                console.log('load complete');
            });
            break;
        case "author":  //导师模块
            require(['zepto', 'sm', 'smExtend', 'base', "author"], function () {
                console.log('load complete');
            });
            break;
        case "product":  //产品列表
            require(['zepto',"touch", 'sm', 'smExtend', 'base', "product"], function () {
                console.log('load complete');
            });
            break;
        case "broadcast":  //直播间
            require(['zepto', 'sm', 'smExtend', 'base', "broadcast"], function () {
                console.log('load complete');
            });
            break;
        case "reading":  //绘本带读
            require(['zepto', 'sm', 'smExtend', 'base', "reading"], function () {
                console.log('load complete');
            });
            break;
        case "payment":  //支付
            require(['zepto', 'sm', 'smExtend', 'smCityPicker', 'base', "payment"], function () {
                console.log('load complete');
            });
            break;
        case "share":  //分享
            require(['zepto', 'base'], function () {
                console.log('load complete');
            });
            break;
        default:
            require(['zepto', 'sm'], function () {
                console.log('load complete');
            });
            break;
    }

}
